package models.issue;

import models.UUIDModel;
import models.admin.AdminUser;
import models.constants.DeletedStatus;
import models.enums.IssueSubType;

import javax.persistence.*;
import java.util.List;

/**
 * Created by hanbin on 17/1/11.
 */
@Entity
@Table(name = "is_subtype_relations")
public class IssueSubtypeRelation extends UUIDModel {

    /**
     * 系统用户
     */
    @JoinColumn(name = "admin_user_id")
    @ManyToOne
    public AdminUser adminUser;

    /**
     * 分支类型
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "issue_sub_type", length = 50)
    public IssueSubType issueSubType;


    /**
     *
     * @param adminUserId
     * @return
     */
    public static List<IssueSubtypeRelation> loadByAdminUser(long adminUserId){
        return IssueSubtypeRelation.find("adminUser.id = ? and deleted = ?" , adminUserId , DeletedStatus.UN_DELETED).fetch();
    }

    /**
     * 根据用户删除
     * @param userId
     */
    public static void deleteByUserId(long userId){
        IssueSubtypeRelation.delete("adminUser.id = ?" ,userId);
    }

}
